const timeout = 20

export default class {
    queue = []

    pushTask(task) {
        this.queue.push(task)
    }

    // open 任务需要插队
    unShiftTask(task) {
        this.queue.unshift(task)
    }

    async start() {
        setTimeout(async () => {
            // this.console('start')
            if (this.queue.length > 0) {
                const task = this.queue.shift()
                await go(task)
            }
            await this.start()
        }, timeout);
    }

    console(msg) {
        // console.log(msg, this.queue.length)
    }
}

async function go(task) {
    await task()
}